package cuiyt.offer;

/**
 * @author cyt
 * @create 2020-05-20 10:30
 */
public class T15 {

    public static void main(String[] args) {

    }

    public ListNode1 FindKthToTail(ListNode1 head, int k) {
        if (head == null) {
            return head;
        }
        int len = 0;
        ListNode1 node = head;
        while (node.next != null) {
            len++;
            node = node.next;
        }
        if (k == len + 1) return head;
        if (k > len) {
            ListNode1 kk = new ListNode1(0);
            kk = null;
            return kk;
        }
        int ans = len - k + 1;
        for (int i = 0; i < ans; i++) {
            head = head.next;
        }
        return head;
    }


}


class ListNode1 {
    int val;
    ListNode1 next = null;

    ListNode1(int val) {
        this.val = val;
    }

}


